{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "62b4e84c-7eed-4a56-add0-fca6e568c12b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1937608c-9b84-4bdd-a03d-53bd8845cf17",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取图片\n",
    "img = cv2.imread('test1.png')\n",
    "\n",
    "cv2.imshow('original', img)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2e53a541-1075-45e2-8a6f-5f13dd81cbd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 灰度化\n",
    "gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
    "\n",
    "cv2.imshow('gray', gray)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "33c14b3d-264a-4d78-8f08-fcea846a94ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建sift对象\n",
    "sift = cv2.xfeatures2d.SIFT_create()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4fcf8ef2-806a-4d80-a075-04cba654f081",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 进行检测\n",
    "kp = sift.detect(gray, None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "47598efb-7f8a-4f0f-a1e3-7b38c0aac942",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'cv2' has no attribute 'destoryAllWindows'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[6], line 6\u001b[0m\n\u001b[0;32m      4\u001b[0m cv2\u001b[38;5;241m.\u001b[39mimshow(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msift\u001b[39m\u001b[38;5;124m'\u001b[39m, img)\n\u001b[0;32m      5\u001b[0m cv2\u001b[38;5;241m.\u001b[39mwaitKey(\u001b[38;5;241m0\u001b[39m)\n\u001b[1;32m----> 6\u001b[0m cv2\u001b[38;5;241m.\u001b[39mdestoryAllWindows()\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'cv2' has no attribute 'destoryAllWindows'"
     ]
    }
   ],
   "source": [
    "# 绘制keypoints\n",
    "cv2.drawKeypoints(gray, kp, img)\n",
    "\n",
    "cv2.imshow('sift', img)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e19da0a-6514-4496-ab33-bf22546be04a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
